home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / Play sound 1.0-OSAX / Play-osax.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-19  |  4.1 KB  |  153 lines  |  [TEXT/KAHL]

  1. /*-------- Play a sound osax by PAUTEX jf 12/93 ----- */
  2. /* this file for demo about how to wrire an OSAX for Applescript */
  3. /* contact by mail for other details 
  4.    
  5.    e-mail pautex@lpmi.u-nancy.fr
  6.    
  7. */
  8. #include <Aliases.h>
  9.  
  10. int Sound(int n);
  11. int SoundN(Str255 nom);
  12. /********************************* ORIGINE *********************************************/
  13. pascal main(AppleEvent *theAEvt, AppleEvent *reply, long *theRefCon)
  14. {
  15. int                i,myErr,nb,pf1,soundID=0;
  16. DescType        returnedType;
  17. char            mynom[256];
  18. Str255            nom;
  19. Size            actualSize = 0;
  20. Size            dataSize = 4,optionSize;
  21. Size            nomSize = 0,typeSize;
  22. OSType            creator = 'ttxt',filetype = 'TEXT';        /* default */
  23. FSSpec            myFSS;
  24. long            option,ID;
  25. int                currentFile;
  26. int                byname = 0,all = 0;
  27.  
  28. /* ------------ extraction du ID sound a faire */
  29. myErr = AEGetParamPtr(theAEvt,'----',typeInteger,&returnedType,&ID,4,&dataSize);     /*keyDirectObject*/
  30. if(!myErr) {
  31.     soundID = ID;
  32.     }
  33.     
  34. /* ------------ extraction de type du document si present */
  35. myErr = AEGetParamPtr(theAEvt,'type',typeWildCard,&returnedType,&filetype,4,&typeSize); /*keyDirectObject*/
  36. if(myErr) {
  37.     filetype = 'TEXT';
  38.     }
  39.  
  40. /* ------------ extraction du nom du doc a chercher s'il y a lieu */
  41. myErr = AEGetParamPtr(theAEvt,'name',typeWildCard,&returnedType,&mynom,255,&actualSize); /*keyDirectObject*/
  42. if(!myErr) {
  43.     for(i=0;i<actualSize;i++) nom[i+1] = mynom[i];            /* deplace  chaine */
  44.     nom[0] = actualSize;                                    /* chaine pascal Str255 */
  45.     byname = 1;
  46.     }
  47.  
  48. /* ------ option de remplacement yes/no */    
  49. myErr = AEGetParamPtr(theAEvt,'alll',typeWildCard,&returnedType,&option,4,&optionSize); /*keyDirectObject*/
  50. if(!myErr) {
  51.     if (returnedType == 'enum') {
  52.         if (option == 'yes ') all = 1;
  53.         if (option == 'no  ') all = 2;
  54.         }
  55.     }
  56.     
  57. /* ------------ extraction du nom du document a lire si present >> passe in file "hh" */
  58. myErr = AEGetParamPtr(theAEvt,'fpth',typeFSS,&returnedType,&myFSS,sizeof(myFSS),&nomSize); /*keyDirectObject*/
  59. if(!myErr) {
  60.     if(returnedType == typeFSS ) {                            /* realise FSS */
  61.         currentFile = CurResFile();
  62.         
  63.         myErr = FSpOpenRF(&myFSS,fsRdPerm,&pf1);
  64.         if(!myErr) {
  65.             FSpOpenResFile(&myFSS,fsRdPerm);
  66.             
  67.             /* ----- decode les options */
  68.             if(all == 0) {
  69.                 if(byname == 0)  Sound(soundID);            /* par id direct */
  70.                 if(byname == 1)  SoundN(nom);
  71.                 }
  72.             if (all == 1) {                                    /* tt les sons */
  73.                 AllSound(0);
  74.                 
  75.                 }
  76.             if (all == 2) {                                    /* tt les sons */
  77.                 AllSound(1);
  78.                 
  79.                 }
  80.             if(pf1 != 0) CloseResFile(pf1);
  81.             }
  82.         }
  83.     }
  84.  
  85. /* ------ Pas de fichier specifié passe au systeme direct */
  86. else {    
  87.     UseResFile(0);                                            /* system */
  88.     myErr = 0;    
  89.     if(all == 0) {
  90.         if(byname == 0)  Sound(soundID);                    /* par id direct */
  91.         if(byname == 1)  SoundN(nom);
  92.         }
  93.     if (all == 1) {                                            /* tt les sons */
  94.         AllSound(0);
  95.         
  96.         }
  97.     if (all == 2) {                                            /* tt les sons */
  98.         AllSound(1);
  99.         }
  100.     }
  101.  
  102. return myErr;
  103. }
  104. /***********************************************************************************************************/
  105. int Sound(int n)                                            /* un son N° n en res */
  106. {
  107. Handle        SynthH;
  108. SynthH = GetResource('snd ',n);                                /* importe le son N° n */
  109.  
  110. if(SynthH != nil) {
  111.     SndPlay(0L,SynthH,FALSE);
  112.     ReleaseResource(SynthH);
  113.     }
  114. }
  115. /***********************************************************************************************************/
  116. int SoundN(Str255 nom)
  117. {
  118. Handle        SynthH;
  119. SynthH = Get1NamedResource('snd ',nom);                        /* importe le son N° n */
  120.  
  121. if(SynthH != nil) {
  122.     SndPlay(0L,SynthH,FALSE);
  123.     ReleaseResource(SynthH);
  124.     }
  125. }
  126. /***********************************************************************************************************/
  127. /* --- tt les son du fichier */
  128. AllSound(int first)
  129. {
  130. Handle        SynthH;
  131. int            nb,index;
  132.  
  133. nb = Count1Resources('snd ');                                /* nb de son ici */
  134.  
  135. if(!first) {
  136.     for(index = 1;index <= nb;index++) {
  137.         SynthH = Get1IndResource('snd ',index);
  138.         if(SynthH != nil) {
  139.             SndPlay(0L,SynthH,FALSE);
  140.             ReleaseResource(SynthH);
  141.             }
  142.         }
  143.     }
  144. else {
  145.     SynthH = Get1IndResource('snd ',1);
  146.     if(SynthH != nil) {
  147.         SndPlay(0L,SynthH,FALSE);
  148.         ReleaseResource(SynthH);
  149.         }
  150.     }
  151. }
  152. /***********************************************************************************************************/
  153.